#include<bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a);i<n;i++)
int a[100100],ans[100100],num[100100],s[100100],b[100100],x[4],p[20],k;
vector<int>d[200100];
char c[20];
void add(int j,int w){
	d[p[k]+j-1].push_back(j);
	for(int i=1;i<=j;i++){
	}
}
int main(){
	freopen("arena.in","r",stdin);
	freopen("arena.out","w",stdout);
	int n,m;
	scanf("%d%d",&n,&m);
	REP(i,1,n+1){
		scanf("%d",&a[i]);
	}
	REP(i,0,m){
		scanf("%d",&num[i]);
		s[i]=num[i];
	}
	sort(s,s+m);
	k=0;
	p[0]=1;
	while(p[k]<n){
		p[k]=p[k-1]*2;
		k++;
	}
	REP(i,0,k){
		cin>>c[i];
	}
	int t;
	cin>>t;
	while(t--){
		scanf("%d%d%d%d",&x[0],&x[1],&x[2],&x[3]);
		REP(i,1,n+1){
			b[i]=a[i]^x[i%4];
		}
		int w=0;
		REP(i,1,n+1){
			if(p[w]<i)w++;
			add(i,w);
		}
	}
	return 0;
}
